<template>
  <div class="chat_item">
    <div class="chat_item__content">
      <div class="chat_text">
        <span class="text" v-if="item.type === 'text'">{{ item.data }}</span>
        <img
          class="image"
          v-if="item.type === 'image'"
          :src="item.data.url"
          alt="图片"
        />
        <video
          class="video"
          controls
          v-if="item.type === 'video'"
          :src="item.data.url"
          alt="视频"
        ></video>
      </div>
    </div>
    <div class="chat_item__avatar">
      <el-avatar :src="item.from_avatar" shape="square" :size="40"></el-avatar>
    </div>
  </div>
</template>

<script setup lang="ts">
defineProps({
  item: {
    type: Object,
    default: () => ({})
  }
})
</script>

<style lang="scss" scoped>
.chat_item {
  display: flex;
  justify-content: flex-end;
  margin-bottom: 10px;

  .chat_item__avatar {
    margin-left: 10px;
  }

  .chat_item__content {
    max-width: 250px;
    .chat_text {
      font-size: 15px;
      color: #333;
      padding: 10px;
      box-sizing: border-box;
      border-radius: 5px;
      position: relative;
      background-color: #07c160;

      .image {
        width: 100%;
        height: 100%;
        border-radius: 5px;
      }

      .video {
        width: 100%;
        height: 100%;
        border-radius: 5px;
      }
    }
    .chat_text::before {
      content: '';
      position: absolute;
      top: 10px;
      right: -5px;
      width: 0px;
      height: 0%;
      border-top: 5px solid transparent;
      border-left: 5px solid #07c160;
      border-bottom: 5px solid transparent;
    }
  }
}
</style>
